﻿//(1)modification: 28/01/14 Pau and Alejandra
//last modification: 06/02/14 Pau and Alejandra
/*
Introduces redraw with the list of the files with getFiles() -- FileList
Introduces position and total of files with getSize() --FileList
.../*/
using System;

namespace DamCommander
{
    class Panel
    {
        // protected bool finished = false;
        protected int posX;
        protected int currentX;
        protected int posY;
        protected int currentY;
        protected int width;
        protected int height;
        protected string path;
        protected bool active;
        protected FileList files;
        // protected ConsoleKeyInfo myKey;

        public Panel(int posX, int posY, int width, int height, string path)
        {
            this.posX = posX;
            this.currentX = posX;
            this.posY = posY;
            this.currentY = posY;
            this.width = width;
            this.height = height;
            this.path = path;
            this.active = false;
            files = new FileList(path);

        }

        public void Header()
        {
            Console.SetCursorPosition(posX, posY);
            for (int i = 0; i < (width - path.Length - 2) / 2; i++)
            {
                Console.Write("-");
            }
            Console.Write(" " + path + " ");
            for (int i = 0; i < (width - path.Length - 2) / 2; i++)
            {
                Console.Write("-");
            }

            currentY = posY + 1;
            Console.SetCursorPosition(posX, currentY);
            for (int i = 0; i < width; i++)
            {
                Console.Write("-");
            }

            currentY++;
        }

        public void Redraw()
        {
            // To-DO: Control the amount of files, we have a small window
            // Optional, include size or something else

            Header();
            Console.SetCursorPosition(posX, currentY);
            Console.ForegroundColor = ConsoleColor.Blue;
            files.ShowList(currentY);


            currentY = posY + 2; // initial Y + 2 header lines

            Console.SetCursorPosition(currentX + 1, currentY);
        }

        public void ChangePath()
        {

        }

        //MOVE DOWN FILES IN THE SAME PANEL 
        public void MoveDown()
        {
            // Optional: Check if there are files or we are just moving "nowhere"
            if (currentY < 22)
                currentY++;
            Console.SetCursorPosition(currentX + 1, currentY);
        }

        //MOVE UP FILES IN THE SAME PANEL 
        public void MoveUp()
        {
            if (currentY <= 5)
                currentY = 5;
            else
                currentY--;
            Console.SetCursorPosition(currentX + 1, currentY);
        }

        ////MOVE TO THE RIGHT PANEL
        //public void MoveRight()
        //{
        //    Console.SetCursorPosition(posX, posY);
        //    if (myKey.Key == ConsoleKey.RightArrow)
        //        posX++;
        //        Console.ForegroundColor = ConsoleColor.Yellow;
        //}

        ////MOVE TO THE LEFT PANEL
        //public void MoveLeft()
        //{
        //    Console.SetCursorPosition(posX, posY);
        //    if (myKey.Key == ConsoleKey.LeftArrow)
        //        posX--;
        //    Console.BackgroundColor = ConsoleColor.Blue;
        //}


        public void LaunchCurrentItem()
        {
            // System.Diagnostics.Process.Start(@"C:\\Users\Z510\Desktop\prueba.txt");
            // TO - DO:
            // This way works, you just need to put the correct path
            // And if we show directories, check if its a directory or a file
            // and do different things, if it's a directory, you must change the path
            // if it's a file, open it that way (or another of your choice)
        }

        public void Activate()
        {
            active = true;
        }

        public void DeActivate()
        {
            active = false;
        }

        public bool GetActive()
        {
            if (active)
                return true;
            return false;
        }

        public int GetX()
        {
            return posX;
        }

        public int GetY()
        {
            return posY;
        }

        public int GetCurrentX()
        {
            return currentX;
        }

        public int GetCurrentY()
        {
            return currentY;
        }
    }
}
